<?php
Class BaseModel Extends CI_Model
{
	var $select;
	var $from;
	var $join;
	var $joinon;
	var $joinoption;
	var $where;
	var $groupby;
	var $having;
	var $orderby;
	var $limit;
	
	function insert($modelName, $dataArray)
	{
		$result = $this->db->insert($modelName, $dataArray);
		return $result;
	}
	
	function update($modelName, $id, $dataArray)
	{
		$this->db->where('Id', $id);
		$result = $this->db->update($modelName, $dataArray);
		return $result;
	}
	
	function gets()
	{
		$result = array();
		if($this->select == NULL)
		{
			return 'select is empty.';
		}
		if($this->from == NULL)
		{
			return 'from is empty.';
		}
		$this->db->select($this->select);
		$this->db->from($this->from);
		if($this->join != NULL)
		{
			$this->db->join($this->join, $this->joinon, $this->joinoption);
		}
		if($this->where != NULL)
		{
			$this->db->where($this->where);
		}
		if($this->groupby != NULL)
		{
			$this->db->group_by($this->groupby);
		}
		if($this->having != NULL)
		{
			$this->db->having($this->having);
		}
		if($this->orderby != NULL)
		{
			$this->db->order_by($this->orderby);
		}
		if($this->limit != NULL)
		{
			$this->db->limit($this->limit);
		}
		$query= $this->db->get();
		$index = 1;
		foreach ($query->result() as $row)
		{
			$result[$index++] = $row;
		}
		return $result;
	}
	
	function getById($modelName, $Id)
	{
		$query = $this -> db -> query('select * from '.$modelName.' where Id='.$Id);
		if($query -> num_rows() > 0)
		{
			$rows = $query -> row_array();
		}
		return $rows;
	}
}
?>